Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we use in our program. These data types have different storage capacities.
1. Primitive Data Types
These are the fundamental data types in C, used to define variables that hold simple values.
A. Integer Types (int)
- int: Used to store integers (whole numbers), typically 4 bytes in size.
Example:int a = 5; - short: A smaller integer type, typically 2 bytes.
Example:short b = 100; - long: A larger integer type, typically 4 or 8 bytes.
Example:long c = 100000; - long long: An even larger integer type, typically 8 bytes.
Example:long long d = 123456789012345;
Floating-point Types
- float: Typically used to store floating-point numbers, with 4 bytes of memory.
Example:float f = 3.14; - double: A double-precision floating-point type, typically 8 bytes.
Example:double d = 3.14159265358979; - long double: Even more precision than double.
Example:long double ld = 3.1415926535897932384626433832795;
C. Character Type
- char: Typically used to store a single character (1 byte).
Example:char ch = 'A'; - signed char: Can store values between -128 to 127.
- unsigned char: Can store values between 0 to 255.
2. Derived Data Types
- Arrays: A collection of variables of the same data type.
- Pointers: Variables that store the address of another variable.
3. User Defined Data Types
- Unions (union): Stores different data types in the same memory location but only one at a time.
- Enumerations (enum): A set of named integer constants.
- Structures (struct): Groups different types of variables together.